spinbutton: Interpret localized digits
authorMatthias Clasen <mclasen@redhat.com>
Tue, 24 Nov 2020 18:42:29 +0000 (13:42 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 8 Mar 2021 22:49:21 +0000 (17:49 -0500)
Interpret input where the characters have numeric values.

See #3387

gtk/gtkspinbutton.c

index 88ae86ad974df896eebe5913b9222b11e93a6af2..a56bfb6f0413856abff8f6a73489472d06181c7b 100644 (file)
@@ -1602,9 +1602,35 @@ gtk_spin_button_default_input (GtkSpinButton *spin_button,
 
   *new_val = g_strtod (text, &err);
   if (*err)
-    return GTK_INPUT_ERROR;
-  else
-    return FALSE;
+    {
+      /* try to convert with local digits */
+      gint64 val = 0;
+      int sign = 1;
+      const char *p;
+
+      for (p = text; *p; p = g_utf8_next_char (p))
+        {
+          gunichar ch = g_utf8_get_char (p);
+
+          if (p == text && ch == '-')
+            {
+              sign = -1;
+              continue;
+            }
+
+          if (!g_unichar_isdigit (ch))
+            break;
+
+          val = val * 10 + g_unichar_digit_value (ch);
+        }
+
+      if (*p)
+        return GTK_INPUT_ERROR;
+
+      *new_val = sign * val;
+    }
+
+  return FALSE;
 }
 
 static void